package com.example.springhook;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class MyAware implements ApplicationContextAware, BeanNameAware, BeanFactoryAware, InitializingBean {

    String name;

    MyAware(){
        System.out.println("1.MyService构造方法");
    }

    @Override
    public void setBeanName(String name) {
        this.name = name;
        System.out.println("BeanNameAware.setBeanName："+name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("BeanFactoryAware.setBeanFactory："+beanFactory);
    }

    public void initMethod(){
        System.out.println("MyService的initMethod");
    }

    public void destroyMethod(){
        System.out.println("MyService的destroyMethod");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("ApplicationContextAware的setApplicationContext："+applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean.afterPropertiesSet");
    }
}
